package com.project.personalfundmanager.client.taxitems;

import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.project.personalfundmanager.client.common.Const;
import com.project.personalfundmanager.shared.models.Section80CModel;

public class Section80CItem extends ParentItem<Section80CModel>
{
	public static final int TOTAL80CLIMIT = 100000;
	NumberField totalBox;

	public Section80CItem( Section80CModel model )
	{
		super( model );
	}

	@Override
	public void addFormComponents( FormPanel formPanel, boolean isEditable )
	{
		addToPanel(formPanel,uiHelper.getNumberField( "EPF / PPF Contribution", Const.PF, isEditable, TOTAL80CLIMIT ) );
		addToPanel(formPanel,uiHelper.getNumberField( "LIC Premium", Const.LIC, isEditable, TOTAL80CLIMIT ) );
		addToPanel(formPanel,uiHelper.getNumberField( "Post Office Saving Scheme", Const.POST_OFFICE, isEditable, TOTAL80CLIMIT ) );
		addToPanel(formPanel,uiHelper.getNumberField( "Saving in NSC", Const.NSC, isEditable, TOTAL80CLIMIT ) );
		addToPanel(formPanel,uiHelper.getNumberField( "Saving in NSS", Const.NSS, isEditable, TOTAL80CLIMIT ) );
		addToPanel(formPanel,uiHelper.getNumberField( "Mutual Fund", Const.MUTUAL_FUND, isEditable, TOTAL80CLIMIT ) );
		addToPanel(formPanel,uiHelper.getNumberField( "Replayment of House Loan", Const.HOUSE_LOAN, isEditable, TOTAL80CLIMIT ) );
		addToPanel(formPanel,uiHelper.getNumberField( "Tution Fees for Child Education", Const.TUTION_FEES, isEditable, TOTAL80CLIMIT ) );
		addToPanel(formPanel,uiHelper.getNumberField( "Taxsaving FD", Const.FD, isEditable, TOTAL80CLIMIT ) );
		addToPanel(formPanel,uiHelper.getNumberField( "NHB Scheme", Const.NHB, isEditable, TOTAL80CLIMIT ) );
	}

	@Override
	public void addTotalComponents( FormPanel totalPanel )
	{
		totalBox = uiHelper.getNumberField( "Total", Const.SEC80_TOTAL, false );
		addToPanel( totalPanel,totalBox );
	}

	@Override
	public void calculateTotal()
	{
		int total = model.getPF() + model.getLIC() + model.getPostOffice() + model.getNSC() + model.getNSS() + model.getMutualFund() + model.getHouseLoan() + model.getTutionFees() + model.getFD() + model.getNHB();

		if ( total > TOTAL80CLIMIT )
			model.setTotal( TOTAL80CLIMIT );
		
		model.setTotal( total );
	}
}
